import request from "./request";
// 上传图片
export function uploadImg(data,vm) {
  return request({
    url: "users/updateIcon?token=" + sessionStorage.getItem("token"),
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data: data,
  }).then((response) => {
    // console.log(response);
      if (vm && vm.$message) {
        vm.$message({
          message: response.data && response.data.message || "上传成功",
          type: "success",
        });
      return response.data;
    } else {
      const error = new Error(response.statusText);
      error.response = response;
      throw error;
    }
  }).catch((error) => {
    if (vm && vm.$message) {
      vm.$message({
        message: "上传失败：" + (error.response && error.response.data && error.response.data.message || error.message),
        type: "error",
      });
    }
    throw error; // 抛出错误，以便在调用者中捕获
  });

}
